/*
 * Created on 2006-2-27
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.toyi.db;

import java.io.IOException;
import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

/**
 * @author yangbingxp
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class SqlMapFactory {

	private static SqlMapClient sqlMap;

	private SqlMapFactory() {
		Reader reader = null;
		try {
			reader = Resources.getResourceAsReader("config/sql-map-config.xml");
			sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null)
				try {
					reader.close();
				} catch (IOException e) {
				}
		}
	}

	public static synchronized SqlMapClient getSqlMap() {
		if (sqlMap == null) {
			new SqlMapFactory();
		}
		return sqlMap;
	}
}